﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

using HR_Implements;

namespace EmployeeHost
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        TcpChannel channel = null;


        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                EmployeeRemoteObject emp = new EmployeeRemoteObject();
                



                BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
                //SoapServerFormatterSinkProvider serverProvider = new SoapServerFormatterSinkProvider();
                serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

                System.Collections.IDictionary props = new System.Collections.Hashtable();
                props["port"] = int.Parse(txt_port.Text);

                 channel = new TcpChannel(props, null, serverProvider);



                RemotingConfiguration.RegisterWellKnownServiceType(typeof(EmployeeRemoteObject), "EMRemoteObject", WellKnownObjectMode.SingleCall);
                ChannelServices.RegisterChannel(channel);
                lbl.Text = "Start";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                ChannelServices.UnregisterChannel(channel);
                lbl.Text = "Stop";


            }
            catch (Exception ex)
            {
                lbl.Text = "Error";
                MessageBox.Show(ex.Message);
            }
        }
    }
}
